package com.yitiao.demo100;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

/**
 * 从键盘输入一个数字，打印出该数字的绝对值。
 */
public class question_02 {
    public static void main(String[] args) throws IOException {
        question_02 question02 = new question_02();
//        question02.method1();
        question02.method2();
        question02.method3();
    }
    //System.in
    public void method1() throws IOException {
        System.out.println("Please Enter Data:");
        char i = (char)System.in.read();
        System.out.println("System.in --> "+Math.abs(i-'0'));
    }
    //InputStreamReader
    public void method2() throws IOException {
        System.out.println("Please Enter Data:");
        //new一个InputStreamReader对象
        InputStreamReader is = new InputStreamReader(System.in);
        //BufferedReader的有参构造的方法
        BufferedReader br = new BufferedReader(is);
        //读取一行，抛出异常
        String line = br.readLine();
        System.out.println("InputStreamReader --> "+Math.abs(Integer.parseInt(line)));
    }
    //Scanner
    public void method3(){
        System.out.println("Please Enter Data:");
        Scanner sc = new Scanner(System.in);
        //读取int
        int i = sc.nextInt();
        //String s = sc.nextLine();  读取字符串型输入
        //float f = sc.nextFloat();  读取float型输入
        System.out.println("Scanner --> "+Math.abs(i));
    }
}


